import json
import os


def json_file_to_dict(file):
    with open(file, 'r') as f:
        dict = json.load(fp=f)
        #print(dict)  # 'name': 'many', 'age': 10, 'sex': 'male'
        return dict

def get_day(a,num):
    day = 'DAY' + str(num)
    new = {
        'JBL1': a['solver1'][day]['D1'],
        'JBL2': a['solver1'][day]['D2'],
        'JBL3': a['solver1'][day]['D3'],
        'JBL4': a['solver1'][day]['D4'],
        'JBL5': a['solver1'][day]['D5'],
        'JBL6': a['solver1'][day]['D6'],
        'JBL7': a['solver1'][day]['D7'],
        'JBL8': a['solver1'][day]['D8'],
        'JBL9': a['solver1'][day]['D9'],
        'JBL10': a['solver1'][day]['D10'],
        'JBL11': a['solver1'][day]['D11'],
        'JBL12': a['solver1'][day]['D12'],
        'JBL13': a['solver1'][day]['D13'],
        'JBL14': a['solver1'][day]['D14'],
        'JBL15': a['solver1'][day]['D15']
    }
    return new

def prcess_one_week(file):
    a = json_file_to_dict(file)
    week = []
    for i in range(7):
        b = i + 1
        c = get_day(a, b)
        week.append(c)
    return week


import json

def dict_to_json_write_file(dict):
    with open('test.json', 'w') as f:
        json.dump(dict, f)


if __name__ == '__main__':
    dir = 'test'
    all = []
    for file in os.listdir(dir):
        file_path = os.path.join(dir, file)
        week = prcess_one_week(file_path)
        all.append(week)
    dict_to_json_write_file(all)